﻿
using FreeScheduler;

namespace Simple.WebAi.Extensions
{
    public static class FreeSchedulerExtension
    {
        public static void AddFreeScheduler(this IServiceCollection services)
        {
            var config = services.BuildServiceProvider().GetService<IConfiguration>()!;
            var scheduler = new FreeSchedulerBuilder()
             .OnExecuting(task =>
             {
                 Console.WriteLine("执行任务,时间:" + DateTime.Now.ToString("yyyy-MM-dd"));
                 if (task.Topic == "语音识别")
                 {
                     // 进行语音识别的处理
                 }
             })
            .UseTimeZone(TimeSpan.FromHours(8))
            .Build();
            services.AddSingleton(scheduler);

            // 语音识别
            scheduler.AddTask("语音识别", "语音识别", -1, 60 * 5);
        }
    }
}
